import datetime

def calculate_age_and_days(birth_date):
    """计算年龄和出生天数"""
    today = datetime.date.today()
    
    # 计算年龄
    age = today.year - birth_date.year
    if (today.month, today.day) < (birth_date.month, birth_date.day):
        age -= 1
    
    # 计算出生天数
    birth_days = (today - birth_date).days
    
    return age, birth_days

def main():
    print("📅 年龄与出生天数查询工具 📅")
    print("=" * 40)
    
    while True:
        try:
            # 获取用户输入
            birth_str = input("\n请输入您的出生日期(格式:YYYY-MM-DD)，输入q退出: ")
            if birth_str.lower() == 'q':
                break
                
            # 解析日期
            birth_date = datetime.datetime.strptime(birth_str, "%Y-%m-%d").date()
            today = datetime.date.today()
            
            # 检查未来日期
            if birth_date > today:
                print("⚠️ 出生日期不能晚于今天！")
                continue
            
            # 计算结果
            age, days = calculate_age_and_days(birth_date)
            
            # 计算下一个生日
            next_birthday = datetime.date(today.year, birth_date.month, birth_date.day)
            if next_birthday < today:
                next_birthday = next_birthday.replace(year=today.year + 1)
            days_to_birthday = (next_birthday - today).days
            
            # 显示结果
            print("\n" + "=" * 40)
            print(f"📌 出生日期: {birth_date.strftime('%Y年%m月%d日')}")
            print(f"🎂 您的年龄: {age}岁")
            print(f"⏳ 您已出生: {days:,}天")
            print(f"🎁 距离下次生日还有: {days_to_birthday}天")
            
            # 特殊年龄提示
            if age == 18:
                print("\n🎉 恭喜您成年了！")
            elif age == 60:
                print("\n🎊 花甲之年，祝您健康长寿！")
            elif age == 100:
                print("\n💐 百岁寿星，福如东海寿比南山！")
            
            print("=" * 40)
            
        except ValueError:
            print("⚠️ 输入格式不正确，请按YYYY-MM-DD格式输入，例如:1990-05-15")
        except Exception as e:
            print(f"发生错误: {e}")

if __name__ == "__main__":
    main()